from flask import Flask, jsonify
from flask_cors import CORS

from util import util

app = Flask(__name__)
CORS(app)


@app.route('/api/hello', methods=['GET'])
def hello():
    return jsonify({'message': 'Hello, world!'})


@app.route('/api/actor', methods=['GET'])
def getActor():
    rst = util.execute_query("select * from actor limit 5")
    return jsonify(rst)

# http://127.0.0.1:5000/api/actor/16


@app.route('/api/actor/<actorid>', methods=['GET'])
def getActorById(actorid):
    rst = util.execute_query(f"select * from actor where actor_id = {actorid}")
    return jsonify(rst)


if __name__ == '__main__':
    app.run()
